# -*- coding: utf-8 -*-
"""
Created on Sat Apr 22 14:25:01 2023

@author: 52224
"""
#=****载入相应函数****=#


def Test_Inverter_Transfer(B1500,Vin_setup,Vgnd_Unit,Vdd_Unit,Iout_Unit,
                           Iin_comp1=10e-6,Range_Vin='Limited 1nA',
                           Voltage_gnd=0,Ignd_comp=1e-2,Range_gnd='Limited 1nA',
                           Voltage_vdd=-999,Idd_comp=1e-2,Range_vdd='Limited 1nA',
                           Iout=0,Vout_comp=6,Range_out='Limited 0.5V'):
    Unit1=Vin_setup[0]
    VName1='Vin'
    Direction1='Double Linear'
    Start1=Vin_setup[1]
    end1=Vin_setup[2]
    nop1=Vin_setup[3]
    Icomp1=Iin_comp1
    Range1=Range_Vin
    VAR_setup=[Unit1,VName1,Direction1,Start1,end1,nop1,Icomp1,Range1]
    Unit2=Vgnd_Unit
    VName2='Vgnd'
    Voltage2=Voltage_gnd
    Icomp2=Ignd_comp
    Range2=Range_gnd
    Unit3=Vdd_Unit
    VName3='Vdd'
    if Voltage_vdd != -999:
        Voltage3=Voltage_vdd
    else:
        Voltage3=max(Vin_setup[1],Vin_setup[2])
    Icomp3=Idd_comp
    Range3=Range_vdd
    Unit4=Iout_Unit
    IName4='Iout'
    Current4=Iout
    Vcomp4=Vout_comp
    Range4=Range_out
    Measurement_setup=[Unit2,VName2,Voltage2,Icomp2,Range2,
                   Unit3,VName3,Voltage3,Icomp3,Range3,
                   Unit4,IName4,Current4,Vcomp4,Range4]
    return IV_sweept(B1500,VAR_setup,Measurement_setup)

from B1500 import IV_sweept
import matplotlib.pyplot as plt
#=****载入B1500****=#
import pyvisa
rm=pyvisa.ResourceManager()
B1500=rm.open_resource('GPIB0::17::INSTR')
B1500.timeout=60000
B1500.write('*RST')
B1500.write('CN 1,2,3,4')
#=****定义Inverter Transfer曲线测试常量****=#
Vin_Unit='3'                                        #VIN对应的物理端口
Vin_Vstart=0                                        #VIN扫描的起始电压(GND)
Vin_Vend=1                                          #VIN扫描的终点电压(VDD)
Vin_Nop=101                                         #VIN扫描点的数目
Vin_setup=[Vin_Unit,Vin_Vstart,Vin_Vend,Vin_Nop]    #VIN扫描参数打包
Vgnd_Unit='4'                                       #Vgnd对应的物理端口
Vdd_Unit='1'                                        #Vdd对应的物理端口
Iout_Unit='2'                                       #VOUT对应的物理端口
                                                      #这里没有写并行测多个器件，但是扩展几行就搞定了（这块伊蓓当时扩展了），下次找她拿
data=Test_Inverter_Transfer(B1500,Vin_setup,Vgnd_Unit,Vdd_Unit,Iout_Unit)
import numpy as np
data1=np.float32(data[1:,:])
plt.plot(data1[:,0],data1[:,-1])